const axios = require('axios');
const moment = require("moment");

let access_token = null;



async function getAccessToken() {
  let res = await axios.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxeb792818461c84a8&secret=cf1bc1ae8cb6228a620cf9a7b7a2d554")
  console.log("res======", res.data);
  access_token = res.data.access_token;
}

exports.xiaochengxuLogin = async function (appid, appSecrect) {

}
exports.getXiaochengxuUrlScheme = async function (path, query) {
  if (access_token == null) {
    await
      getAccessToken();
  }
  let params = {
    jump_wxa: {
      path,
      query
    },
    expire_type: 0,
  };
  let res = await axios.post(`https://api.weixin.qq.com/wxa/generatescheme?access_token=${access_token}`, params).then(function (response) {
    return response.data;
  })
    .catch(function (error) {
      // res.send({
      //   status: '500',
      //   message: error
      // })
    });
  console.log("res===", res);
  return res;
};



setInterval(async () => {
  getAccessToken();
}, 300 * 1000)
getAccessToken();



